//    Copyright (C) Kherty.  All rights reserved.
namespace OpenLS.Spreadsheet
{
    public class BeginsWithFormattingRule : StandardConditionalFormattingRule
    {
        internal override ConditionalFormattingType Type
        {
            get { return ConditionalFormattingType.BeginsWith; }
        }
        internal override bool Apply(Cell cell)
        {
            string s = cell.Value as string;
            var b = s != null && s.StartsWith(Text);
            return ApplyStyle(cell, b);

        }
        internal override void PrepareBeforeWrite(ConditionalFormatting conditionalFormatting, ConditionalFormattingRule.FormatType formatType)
        {
            if (formatType == FormatType.Biff)
            {
                this.Formula1 = string.Format("=LEFT({0},{1}) = \"{2}\"", conditionalFormatting.Range.TopLeftCell.Label, Text.Length, EscapedText);
            }
        }
    }
}
